package com.example.demo.poc.executor;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class FormulaProcessor {

    private ScriptEngine engine;



    public FormulaProcessor() {
        ScriptEngineManager manager = new ScriptEngineManager();
        this.engine = manager.getEngineByName("AviatorScript");
    }

    public void put(String key, Object cxt) {
        this.engine.put(key, cxt);

    }


    public Object exec(String formula) {
        Object o = null;
        try {
            o = this.engine.eval(formula);
        } catch (ScriptException e) {
            e.printStackTrace();
        }
        return o;
    }


}
